package com.gutai.admin.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gutai.admin.biz.login.LoginService;
import com.gutai.admin.common.entity.LoginUser;
import com.gutai.admin.common.entity.response.Response;
import com.gutai.admin.common.util.ResponseHelper;

/**
 * 
 * 
 * 
 * <pre>
 * HISTORY
 * ****************************************************************************
 *  ID    DATE            PERSON            REASON
 *  1     2019年2月14日         LA.01367604           Create
 * ****************************************************************************
 * </pre>
 * 
 * @author LA.01367604
 * @version 1.0
 */
@RestController
@RequestMapping("/login")
public class LoginController {

    private static final Logger logger = LoggerFactory.getLogger(LoginController.class);

    @Autowired
    private LoginService loginService;

    @CrossOrigin
    @PostMapping("/")
    public Response login(@RequestBody LoginUser entity) {
        if (loginService.checkUserLogin(entity)) {
            return ResponseHelper.buildOk(entity);
        }
        return ResponseHelper.buildFail("登录失败");
    }

    @CrossOrigin
    @PostMapping("/add")
    public Response add(@RequestBody LoginUser entity) {
        if (loginService.addUser(entity)) {
            return ResponseHelper.buildOk(entity);
        }
        return ResponseHelper.buildFail("注册失败");
    }

}
